<?php

namespace Biz\model;


class ShopSpecialGoods extends \Doraemon\pockets\datebase\BaseDbModel
{
    const _CONFIG_FILE_ = 'db_shop';

    const _CONFIG_SELECT_ = 'db_shop';

    const _DATABASE_ = 'shop';

    const _TABLE_NAME = 'shop_special_goods';

    const _SUB_TABLE = false;

    const STATUS_PASSED = 1;
    const STATUS_DELECT = 9;

    const TYPE_SPECIAL_GOODS = 1;
    const TYPE_SPECIAL_ACTIVITY = 2;
    const TYPE_SPECIAL_REGISTER = 3;

    public static $activityType = [
        self::TYPE_SPECIAL_GOODS => '商品专题',
        self::TYPE_SPECIAL_ACTIVITY => '商城活动',
        self::TYPE_SPECIAL_REGISTER => '报名活动',
    ];

    public static function addSpecialGoods($data)
    {
        $ret = self::insert($data);
        if ($ret->errorCode() !== '00000') {
            return false;
        }
        return true;
    }

    public static function updateSpecialGoods($where, $data)
    {
        $ret = self::update($data, $where);
        if ($ret->errorCode() !== '00000') {
            return false;
        }
        return true;
    }


    public static function getSpecialGoodsInfoBySpecialIds($ids, $field = '*')
    {
        $where = [
            "AND" => [
                'special_id' => $ids,
                'status' => self::STATUS_PASSED,
            ]
        ];

        return self::select($field, $where);
    }

    public static function getSpecialIdsByGid($goods_id)
    {
        return self::select('special_id', [
            'goods_id' => $goods_id,
            'status' => self::STATUS_PASSED
        ]);
    }


    public static function getSpecialGoodsBySpecialId($field = '*', $id)
    {

        return self::select($field, [
            'AND' => [
                'special_id' => $id,
                'status' => self::STATUS_PASSED,
            ],
        ]);
    }


    public static function getList($where, $select = '*', $limit = [], $order = [])
    {
        $param = ['AND' => $where];
        if ($limit) {
            $param['LIMIT'] = $limit;
        }
        if ($order) {
            $param['ORDER'] = $order;
        }
        return self::select($select, $param);
    }

}